I was recently asked if we could add a random password generator to one of our applications. Generating inside the Notes client limited my language choices to LotusScript and Formula Language (for the most part). Unfortunately LotusScript doesn't have many of the nice native features of Python or Javascript whereby you can reference individual characters in a string or do other standard string manipulations. The approach I used was to create a Custom Sort for the @Sort() formula whereby each character was compared to the previous via a random number. I hope you find this useful:
LotusScript Version
Dim uCaseLetters As Variant
Dim lCaseLetters As Variant
Dim digits As Variant
Dim symbols As Variant
Dim pw As String
Dim final As Variant
'Add in your mix of upper/lowercase letters, digits and valid symbols for your application
uCaseLetters=Evaluate(|@Explode("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";",")|)
lCaseLetters = Evaluate(|@Explode("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";",")|)
digits=Evaluate(|@Explode("0,1,2,3,4,5,6,7,8,9";",")|)
symbols=Evaluate(|@Explode("@,#,$,%,^";",")|)
Randomize
For i = 1 To 2 'take 2 upper case letters
pw = pw + uCaseLetters( Cint( 25 *Rnd+ 0 )) + ","
Next
For i = 1 To 2 'two digits
pw = pw + digits( Cint( 9 *Rnd+ 0 )) + ","
Next
For i = 1 To 2 'two symbols
pw = pw + symbols( Cint( 4 *Rnd+ 0 ))+ ","
Next
For i = 1 To 4 `finally 4 lowercase letters
pw= pw + lCaseLetters( Cint( 25 *Rnd+ 0 ))+ ","
Next
`A total of 10 chars in our password but they are in order: UCase, Digit, Symbol, LCase and need to be randomized
'Here we create a [Custom Sort] that uses the @Random Number generator to compare each character
final = Evaluate(|@Trim(@Implode(@Sort(@Explode("| + pw + |";",");[CustomSort];@If(@Random < @Random;@True;@False));""))|)
Msgbox final(0)
Formula Version
uppers:="A":"B":"C":"D":"E":"F":"G":"H":"I":"J":"K":"L":"M":"N":"O":"P":"Q":"R":"S":"T":"U":"V":"W":"X":"Y":"Z";
lowers:="a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z";
digits:="0":"1":"2":"3":"4":"5":"6":"7":"8":"9";
symbols:="%":"$":"^":"@":"!";
pw:="";
UC:=3;
DIGIT:=3;
SYMBOL:=3;
TOTAL:=12;
@For(i:=1;i
pw:= pw :uppers[ @Integer(26 * @Random + 1)]
);
@For(i:=1;i
pw:= pw : digits[ @Integer(10 * @Random + 1) ]
);
@For(i:=1;i
pw:= pw: symbols[ @Integer(5 * @Random + 1)]
);
@For(i:=1;i<(TOTAL-UC-SYMBOL-DIGIT);i:=i+1;
pw:= pw : lowers[ @Integer(26 * @Random + 1)]
);
@SetField("randomPassword";@Trim(@Implode(@Sort(pw;[CustomSort];@If(@Random < @Random;@True;@False));"")))